var homeUrl = "";
var uploadUrl = homeUrl + "/oss/upload/";

var page = 1;
var limit = 10;
var table;
var layPage;
var form;
var upload;

/** 后台返回消息状态码 */
WEB_STATUS = {
    SUCCESS: 200,
    ERROR: 500500,
    WARNING: 400100,
    PARAMS_VALID: 400200,
    CLIENT_TOKEN_EXCEPTION: 400300,
    PARAMS_VALID_MSG: 400400,
    HTTP_EX: 400500,
    USER_PASSWORD_NOT_MATCH: 400600,
    NO_LOGIN_USER_INFO: 400400,
    LOCKED_ACCOUNT: 500200,
};

/** layer 弹窗状态码 */
LAYER_STATUS = {
    WARNING: "warning",
    SUCCESS: "success",
    ERROR: "error",
    CONFIRM: "confirm",
    LOCKUP: "lockup",
    UNHAPPY: "unhappy",
    HAPPY: "happy",
    LAYER_TIME: 1500
};

/** 文件上传类型 */
UPLOAD_TYPE = {
    // 通用文件
    FILE_OTHER: 0,
    // 头像
    AVATAR: 1
};

$(function () {
    // ajax 统一添加请求时间戳
    $.ajaxSetup({
        beforeSend: function (jqXHR, settings) {
            if ($.string.contain(settings.url, "?")) {
                settings.url += "?request_time=" + new Date().getTime();
            } else {
                settings.url += "&request_time=" + new Date().getTime();
            }
        }
    });

    /* 关闭弹窗 */
    $("#buttonClose").click(function () {
        $.modal.close();
    });
});


/* 常用方法封装 */
(function ($) {
    $.extend({
        /* 请求封装,统一使用 RESTFUL 接口标准规范 */
        http: {
            /* GET 请求 */
            get: function (url, callback) {
                $.ajax({
                    url: homeUrl + url,
                    type: 'GET',
                    cache: false,
                    success: function (res) {
                        $.http.res(res, callback);
                    },
                    error: function () {
                        $.modal.ajaxError();
                    }
                });
            },
            /* POST 请求 */
            post: function (url, data, callback) {
                $.ajax({
                    url: homeUrl + url,
                    type: 'POST',
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    datatype: "json",
                    success: function (res) {
                        $.http.res(res, callback);
                    },
                    error: function () {
                        $.msg.ajaxError();
                    }
                });
            },
            /* 新增 */
            save: function (url, data) {
                $.http.post(url, data, function (res) {
                    $.http.savePutCallback(res);
                })
            },
            /* 更新 */
            update: function (url, data) {
                $.http.putAjax(url, data, function (res) {
                    $.http.savePutCallback(res);
                });
            },
            putAjax: function (url, data, callback) {
                $.ajax({
                    url: homeUrl + url,
                    type: 'PUT',
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    datatype: "json",
                    success: function (res) {
                        callback(res);
                    },
                    error: function () {
                        $.msg.ajaxError();
                    }
                });
            },
            /* 删除 统一消息提示 */
            remove: function (url, title) {
                $.http.removeMsg(url, '确定删除【' + title + '】信息吗？');
            },
            /* 删除 自定义消息 */
            removeMsg: function (url, msg) {
                layer.confirm('<div style="color: #ff000c">' + msg + '</div>', {
                    icon: 3,
                    title: '系统提示！'
                }, function () {
                    $.http.delAjax(url, function (res) {
                        $.http.res(res, function () {
                            initTable();
                            layer.msg(res.msg, {icon: 1, time: 1500});
                        });
                    })
                });
            },
            /* 删除,请求后台 */
            delAjax: function (url, callback) {
                $.ajax({
                    url: homeUrl + url,
                    type: 'DELETE',
                    cache: false,
                    success: function (res) {
                        callback(res);
                    },
                    error: function () {
                        $.msg.ajaxError();
                    }
                });
            },
            /* promise 封装 ajax */
            ajax: function (options) {
                return new Promise((resolve, reject) => {
                    if (!options.url) {
                        return;
                    }
                    let method = options.method || "GET";
                    let async = options.async || true;
                    let xhr = new XMLHttpRequest()
                    xhr.onreadystatechange = function () {
                        if (4 === this.readyState) {
                            if (200 === this.status) {
                                let data = xhr.response;
                                let code = data.status;
                                if (WEB_STATUS.SUCCESS === code) {
                                    resolve(data);
                                }
                                if (WEB_STATUS.WARNING === code) {
                                    reject(data);
                                }
                            } else {
                                $.modal.msgError("网络连接异常,请联系技术人员!");
                            }
                        }
                    }
                    xhr.onerror = function (err) {
                        $.modal.msgError("网络连接异常,请联系技术人员!");
                    }
                    if ("GET" === method) {
                        let url = options.url;
                        if (options.data) {
                            url = url + "?" + options.data.join('&') + "&_now_time" + Math.random()
                        } else {
                            url += "?_now_time" + Math.random()
                        }
                        xhr.open(method, url, async);
                        xhr.setRequestHeader("Content-Type", "application/x-www-from-urlencoded; charset=UTF-8");
                        xhr.send(null);
                    }
                    if ("DELETE" === method) {
                        xhr.open(method, options.url, async);
                        xhr.send(null);
                    }
                    if ("POST" === method || "PUT" === method) {
                        xhr.open(method, options.url, async);
                        xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
                        xhr.setRequestHeader("datatype", "json");
                        xhr.send(JSON.stringify(options.data));
                        xhr.responseType = "json";
                    }
                })
            },
            /* 新增,修改操作表单返回 */
            savePutCallback(res) {
                $.http.res(res, function () {
                    parent.initTable();  // 刷新父页面表单
                    $.msg.msgOkModel(res.msg);  // 操作成功消息弹窗
                });
            },
            /* 返回信息统一处理,操作成功回调函数返回数据,如果操作失败有其他操作,请勿使用该方法 */
            res: function (res, callback) {
                let code = res.status;
                // 操作成功
                if (WEB_STATUS.SUCCESS === code) {
                    callback(res);
                }
                // 参数校验失败
                if (WEB_STATUS.PARAMS_VALID === code) {
                    $.msg.msgValid(res.msg, res.data);
                }
                // 参数校验失败,自定义返回信息
                if (WEB_STATUS.PARAMS_VALID_MSG === code) {
                    $.msg.msgValidCustom(res.msg);
                }
                // 警告/提示
                if (WEB_STATUS.WARNING === code) {
                    $.msg.msgWarning(res.msg);
                }
                // 错误
                if (WEB_STATUS.ERROR === code) {
                    $.msg.msgError(res.msg);
                }
                // 登录查询没有用户
                if (WEB_STATUS.NO_LOGIN_USER_INFO === code) {
                    $.msg.msgDataError(res.msg, res.data);
                }
                // 登录查询账户被锁
                if (WEB_STATUS.LOCKED_ACCOUNT === code) {
                    $.msg.msgDataError(res.msg, res.data);
                }
                // 密码错误
                if (WEB_STATUS.USER_PASSWORD_NOT_MATCH === code) {
                    $.msg.msgError(res.msg);
                }
                // 没有session,跳转到登录页面
                if (WEB_STATUS.CLIENT_TOKEN_EXCEPTION === code) {
                    top.document.location.href = res.data;
                }
            },
            msg: function (res, callback) {
                let code = res.status;
                if (WEB_STATUS.SUCCESS === code) {
                    callback(res);
                }
                // 参数校验失败
                if (WEB_STATUS.PARAMS_VALID === code) {
                    layer.msg(res.data, {icon: $.modal.icon(LAYER_STATUS.WARNING), time: LAYER_STATUS.LAYER_TIME});
                }
                // 参数校验失败,自定义返回信息
                if (WEB_STATUS.PARAMS_VALID_MSG === code) {
                    layer.msg(res.msg, {icon: $.modal.icon(LAYER_STATUS.WARNING), time: LAYER_STATUS.LAYER_TIME});
                }
                // 警告/提示
                if (WEB_STATUS.WARNING === code) {
                    layer.msg(res.msg, {icon: $.modal.icon(LAYER_STATUS.WARNING), time: LAYER_STATUS.LAYER_TIME});
                }
                // 错误
                if (WEB_STATUS.ERROR === code) {
                    layer.msg(res.msg, {icon: $.modal.icon(LAYER_STATUS.ERROR), time: LAYER_STATUS.LAYER_TIME});
                }
            }
        },

        /* 搜索 */
        searchTable: {
            searchBtn: function () {
                $('#searchBtn').on('click', function () {
                        initTable();
                    }
                );
            }
        },

        /* table 统一处理 */
        table: {
            /**
             *  初始化 layui 表格
             * @param options
             */
            init: function (options) {
                $.table.common(options);
                table.render({
                    elem: '#' + options.id,
                    url: homeUrl + options.url,
                    cols: options.cols,
                    page: false,
                    where: options.where,
                    done: function (res, curr, count) {
                        $.table.page(options, count);
                    }
                });
            },

            /**
             *  layui 分页
             * @param options 初始化表格参数
             * @param count    总条数
             */
            page: function (options, count) {
                layPage.render({
                    elem: options.layPage
                    , count: count
                    , curr: page
                    , limit: limit
                    , theme: options.theme
                    , limits: options.limits
                    , layout: options.layout
                    , jump: function (obj, first) {
                        if (!first) {
                            page = obj.curr;
                            limit = obj.limit;
                            options.initTableFun();
                        }
                    }
                })
            },
            common: function (options) {
                if ($.string.isEmpty(options.id)) {
                    options.id = 'layTable'
                }
                if ($.string.isEmpty(options.url)) {
                    options.url = "/404.html";
                }
                if ($.string.isEmpty(options.cols)) {
                    options.cols = [];
                }
                if ($.string.isEmpty(options.layPage)) {
                    options.layPage = 'layPage'
                }
                if ($.string.isEmpty(options.theme)) {
                    options.theme = '#1E9FFF'
                }
                if ($.string.isEmpty(options.limits)) {
                    options.limits = [10, 15, 30]
                }
                if ($.string.isEmpty(options.layout)) {
                    options.layout = ['prev', 'page', 'next', 'skip', 'refresh', 'limit', 'count']
                }
                if ($.string.isEmpty(options.initTableFun)) {
                    options.initTableFun = initTable;
                }
            }
        },

        /* 文件上传 */
        oss: {
            uploadImg: function (options) {
                $.oss.common(options);
                $.oss.upload(options);
            },
            common: function (options) {
                if ($.string.isEmpty(options.id)) {
                    options.id = "upload";
                }
                if ($.string.isEmpty(options.type)) {
                    options.type = UPLOAD_TYPE.FILE_OTHER;
                }
                if ($.string.isEmpty(options.imgSrc)) {
                    options.imgSrc = 'imgSrc';
                }
                if ($.string.isEmpty(options.inputSrc)) {
                    options.inputSrc = 'inputSrc';
                }
                if ($.string.isEmpty(options.accept)) {
                    // file video audio images
                    // 目前后端接收为 file
                    options.accept = 'file';
                }
                if ($.string.isEmpty(options.exts)) {
                    // 默认 jpg|png|gif|bmp|jpeg
                    // 压缩文件格式 zip|rar|7z
                    // 文档 doc|docx|txt|xlsx|xls|ppt|pptx
                    options.exts = 'jpg|png|gif|bmp|jpeg';
                }
                if ($.string.isEmpty(options.callback)) {
                    options.callback = function (res) {
                        $('#' + options.imgSrc).attr('src', res.data.url);
                        $("#" + options.inputSrc).val(res.data.url);
                    }
                }
            },
            upload: function (options) {
                upload.render({
                    elem: '#' + options.id,
                    url: uploadUrl + options.type,
                    exts: options.exts,
                    xhrFields: {
                        withCredentials: true
                    },
                    done: function (res) {
                        let code = res.status;
                        if (WEB_STATUS.SUCCESS === code) {
                            options.callback(res);
                        } else if (WEB_STATUS.ERROR === code) {
                            $.msg.msgError($.oss.msg(options.type) + res.msg);
                        } else {
                            $.msg.msgError("文件上传失败!");
                        }
                    },
                    error: function () {
                        layer.msg("文件上传服务连接失败,请联系技术人员!", {icon: $.modal.icon(LAYER_STATUS.ERROR), time: 1500});
                    }
                });
            }
        },

        msg: {
            // ajax 请求连接错误
            ajaxError: function () {
                $.modal.alert("服务器连接失败，请联系技术人员！", LAYER_STATUS.ERROR);
            },
            // 操作成功,关闭弹窗
            msgOkModel: function (msg) {
                layer.alert(msg, {title: "系统提示", icon: $.modal.icon(LAYER_STATUS.SUCCESS)}, function () {
                    $.modal.close();
                });
            },
            // 错误消息
            msgError: function (content) {
                $.modal.alert(content, LAYER_STATUS.ERROR);
            },
            msgDataWarning: function (msg, data) {
                $.modal.alert('<span style="color: #ff000c"> ' + $.string.replace(msg, "!", "：") + ' </span>' + '<br>' + data, LAYER_STATUS.WARNING);
            },
            msgDataError: function (msg, data) {
                $.modal.alert('<span style="color: #ff000c"> ' + $.string.replace(msg, "!", "：") + ' </span>' + '<br>' + data, LAYER_STATUS.ERROR);
            },
            // 成功消息
            msgSuccess: function (content) {
                layer.msg(content, {
                    icon: 1,
                    time: 1500
                });
            },
            // 警告消息
            msgWarning: function (content) {
                $.modal.alert(content, LAYER_STATUS.WARNING);
            },
            // 请求参数错误,例如:  msg: 请求参数错误;data: 用户名不能为空
            msgValid: function (msg, data) {
                $.modal.alert('<span style="color: #ff000c">' + $.string.replace(msg, "！", "：") + '</span>' + '<br>' + data, LAYER_STATUS.WARNING);
            },
            // 请求参数错误,自定义消息提示,例如: msg: 用户名不能为空
            msgValidCustom: function (msg) {
                $.modal.alert('<span style="color: #ff000c">参数校验错误：</span>' + '<br>' + msg, LAYER_STATUS.WARNING);
            },
        },

        /* 弹出层封装处理 */
        modal: {
            // 显示图标
            icon: function (type) {
                let icon = "";
                if (LAYER_STATUS.WARNING === type) {
                    icon = 0;
                } else if (LAYER_STATUS.SUCCESS === type) {
                    icon = 1;
                } else if (LAYER_STATUS.ERROR === type) {
                    icon = 2;
                } else if (LAYER_STATUS.CONFIRM === type) {
                    icon = 3;
                } else if (LAYER_STATUS.LOCKUP === type) {
                    icon = 4;
                } else if (LAYER_STATUS.UNHAPPY === type) {
                    icon = 5;
                } else if (LAYER_STATUS.HAPPY === type) {
                    icon = 6;
                }
                return icon;
            },
            // 弹出提示
            alert: function (content, type) {
                layer.alert(content, {
                    icon: $.modal.icon(type),
                    title: "系统提示",
                    btn: ['确认'],
                    btnclass: ['btn btn-primary'],
                });
            },
            // 关闭窗体
            close: function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            },
            // 关闭全部窗体
            closeAll: function () {
                layer.closeAll();
            },
            // 单张图片弹出
            openImg(title, url, width, height) {
                parent.layer.open({
                    type: 1,
                    title: title,
                    shadeClose: false,
                    area: [width + 'px', height + 'px'],
                    content: '<img style="width:100%;height:100%"  src="' + url + '" />'
                    , btn: ['关闭']
                    , anim: 5
                    , btn2: function () {
                        layer.closeAll();
                    }
                });
            },
            // 查看，弹出全屏
            openFullSee(title, url) {
                let width = ($(window).width() - 50);
                let height = ($(window).height() - 50);
                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    maxmin: true,
                    shade: 0.3,
                    title: title,
                    content: url,
                    shadeClose: true,
                    btn: ['关闭'],
                    yes: function (index) {
                        return true;
                    }
                });
            },
            // 弹出全屏
            openFull(title, url) {
                let width = ($(window).width() - 50);
                let height = ($(window).height() - 50);
                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    maxmin: true,
                    shade: 0.3,
                    title: title,
                    content: url,
                    shadeClose: true
                });
            },
            // 弹出层指定宽度
            open: function (title, url, width, height) {
                //如果是移动端，就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                if ($.string.isEmpty(title)) {
                    title = false;
                }
                if ($.string.isEmpty(url)) {
                    url = "/404.html";
                }
                if ($.string.isEmpty(width)) {
                    width = 800;
                }
                if ($.string.isEmpty(height)) {
                    height = ($(window).height() - 50);
                }
                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    maxmin: false,
                    shade: 0.3,
                    title: title,
                    content: url,
                    // 弹层外区域关闭
                    shadeClose: false
                });
            },
            see: function (title, url, width, height) {
                //如果是移动端，就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                if ($.string.isEmpty(title)) {
                    title = false;
                }
                if ($.string.isEmpty(url)) {
                    url = "/404.html";
                }
                if ($.string.isEmpty(width)) {
                    width = 800;
                }
                if ($.string.isEmpty(height)) {
                    height = ($(window).height() - 50);
                }
                layer.open({
                    type: 2,
                    content: url,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    maxmin: false,
                    shade: 0.3,
                    title: title,
                    btn: ['关闭'],
                    shadeClose: false,
                    cancel: function (index) {
                        return true;
                    }
                });
            },
            // 禁用按钮
            disable: function () {
                var doc = window.top == window.parent ? window.document : window.parent.document;
                $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
            },
            // 启用按钮
            enable: function () {
                var doc = window.top == window.parent ? window.document : window.parent.document;
                $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
            },
            // 弹出层
            iframe: function (title, url, width, height) {
                layer.open({
                    type: 2,
                    title: title,
                    maxmin: false,
                    shadeClose: false,
                    area: [width + 'px', height + 'px'],
                    content: homeUrl + url
                });
            },
            load: function () {
                layer.load(0, {shade: 0.3});
            }
        },

        /* 字符串处理 */
        string: {
            /* 去掉字符串空格 */
            trim: function (str) {
                return str.replace(/(^\s*)|(\s*$)/g, '');
            },
            // 判断字符串是否为空
            isEmpty: function (value) {
                return (value == null || value === "");
            },
            // 判断一个字符串是否为非空串
            isNotEmpty: function (value) {
                return !$.string.isEmpty(value);
            },
            // 判断字符串 str 里面是否包含目标字符串 value
            contain: function (str, value) {
                return str.indexOf(value) === -1
            },
            // 字符串替换
            replace: function (str, oldChar, newChar) {
                return str.replace(oldChar, newChar)
            }
        },

        /* zTree */
        zTree: {
            /* 初始化 zTree */
            initTree: function (options) {
                if ($.string.isEmpty(options.url)) {
                    $.msg.msgWarning("请填写获取 zTree 数据的地址");
                }
                if ($.string.isEmpty(options.treeId)) {
                    options.treeId = "tree";
                }
                if ($.string.isEmpty(options.initCallback)) {
                    if ($.string.isEmpty(options.setting)) {
                        options.setting = $.zTree.setting(options);
                    }
                    options.initCallback = function (res) {
                        let data = res.data;
                        $.fn.zTree.init($("#tree"), options.setting, data);
                        sitFolderTree = $.fn.zTree.getZTreeObj(options.treeId);
                        let node = sitFolderTree.getNodeByParam("id", "root", null);
                        sitFolderTree.expandNode(node, true, false, true);
                    }
                }
                $.http.get(options.url, options.initCallback);
            },
            /* 获取选中的节点 */
            getCheckedNodes: function (treeId) {
                let treeObj = $.fn.zTree.getZTreeObj(treeId);
                return treeObj.getCheckedNodes(true);
            },
            /* 获取选中的id,返回字符串 */
            getCheckedId: function (treeId) {
                let nodes = $.zTree.getCheckedNodes(treeId);
                if (undefined === nodes || null === nodes
                    || '' === nodes || 0 === nodes.length) {
                    return "";
                }
                let roleCodes = [];
                for (let i = 0; i < nodes.length; i++) {
                    roleCodes[i] = nodes[i].id;
                }
                return roleCodes.join(",");
            },
            /* zTree 设置 */
            setting: function (options) {
                if ($.string.isEmpty(options.check)) {
                    options.check = false;
                }
                if ($.string.isEmpty(options.idKey)) {
                    options.idKey = "id";
                }
                if ($.string.isEmpty(options.pIdKey)) {
                    options.pIdKey = "parentId";
                }
                if ($.string.isEmpty(options.rootPId)) {
                    options.rootPId = "";
                }
                if ($.string.isEmpty(options.showIcon)) {
                    options.showIcon = true;
                }
                if ($.string.isEmpty(options.dblClickExpand)) {
                    options.dblClickExpand = false;
                }
                if ($.string.isEmpty(options.showLine)) {
                    options.showLine = true;
                }
                if ($.string.isEmpty(options.selectedMulti)) {
                    options.selectedMulti = false;
                }
                if ($.string.isEmpty(options.enableSimpleData)) {
                    options.enableSimpleData = true;
                }
                if ($.string.isEmpty(options.callback)) {
                    options.callback = function () {
                        $.msg.msgWarning("请添加回调函数(callback)属性");
                        return false;
                    };
                }
                return {
                    check: {
                        enable: options.check
                    },
                    view: {
                        dblClickExpand: options.dblClickExpand,
                        showLine: options.showLine,
                        selectedMulti: options.selectedMulti,
                        showIcon: options.showIcon
                    },
                    data: {
                        simpleData: {
                            enable: options.enableSimpleData,
                            idKey: options.idKey,
                            pIdKey: options.pIdKey,
                            rootPId: options.rootPId
                        }
                    },
                    callback: {
                        onClick: options.callback
                    }
                };
            },

        },

        select: {
            /* 下拉 */
            func: function (options) {
                if ($.string.isEmpty(options.id)) {
                    $.msg.msgWarning("请传入下拉id")
                    return false;
                }
                if ($.string.isEmpty(options.url)) {
                    $.msg.msgWarning("请传入数据请求地址(url)")
                    return false;
                }
                if ($.string.isEmpty(options.placeholder)) {
                    options.placeholder = '全部';
                }
                if ($.string.isEmpty(options.value)) {
                    options.value = '';
                }
                if ($.string.isEmpty(options.showDefault)) {
                    options.showDefault = false;
                }
                $("#" + options.id + " option").remove();
                if (options.showDefault) {
                    $("#" + options.id + "").append("<option value=''>" + options.placeholder + "</option>");
                }
                if (options.callback) {
                    options.callback = function (res) {
                        let data = res.data;
                        for (let i = 0; i < data.length; i++) {
                            if (data[i].dictValue === options.value) {
                                $("#" + options.id + "").append("<option value=" + data[i].name + " selected>" + data[i].id + "</option>");
                            } else {
                                $("#" + options.id + "").append("<option value=" + data[i].name + ">" + data[i].id + "</option>");
                            }
                        }
                        form.render();
                    }
                }
                $.http.get(options.url, options.callback)
            },
            /* 数据字典下拉 */
            selectDictData: function (options) {
                if ($.string.isEmpty(options.dictType)) {
                    $.msg.msgWarning("请传入数据字典类型")
                    return false;
                }
                options.url = "/api/dict/data/" + options.dictType;
                options.callback = function (res) {
                    let data = res.data;
                    for (let i = 0; i < data.length; i++) {
                        if (data[i].dictValue === options.value) {
                            $("#" + options.id + "").append("<option value=" + data[i].dictValue + " selected>" + data[i].dictLabel + "</option>");
                        } else {
                            $("#" + options.id + "").append("<option value=" + data[i].dictValue + ">" + data[i].dictLabel + "</option>");
                        }
                    }
                    form.render();
                }
                $.select.func(options);
            }
        },

    });
})(jQuery);

/* 返回上一页 */
function goBackPreviousPage() {
    window.history.go(-1);
}